(()=>{
	window.CategoryHelper = class CategoryHelper {
		static getTreeData(ignorePages, onlyAllows) {
			let data = CategoryModelCollector.getAll();
			let treeData = [];
			ignorePages = ignorePages ? ignorePages : [];
			
			for(let i=0; i<data.length; i++) {
				treeData.push({
					id: data[i].getId(),
					name: data[i].getName(),
					parent: data[i].getParent(),
					pId: data[i].getParent(),
					isParent: true
				});
			}
			
			let pages = this.getCategoryPages();
			for(let i=0; i<pages.length; i++) {
				if(ignorePages.indexOf(pages[i].getId()) != -1) {
					continue;
				}
				
				if(onlyAllows && onlyAllows.indexOf(pages[i].getId()) == -1) {
					continue;
				}
				
				treeData.push({
					id: this.getPageTreeId(pages[i].getId()),
					origin_id: pages[i].getId(),
					name: pages[i].getName(),
					parent: pages[i].getCategory(),
					pId: pages[i].getCategory(),
					isParent: false
				});
			}
			
			return treeData;
		}
		
		static getCategoryPages(category) {
			if(category) {
				let pageCollector = new PageModelCollector();
				pageCollector.where('category', category).sort('position', 'ASC').load();
				return pageCollector.get();
			} else {
				return new PageModelCollector().sort('position', 'ASC').load().get();
			}
			
		}
		
		static getPageTreeId(id) {
			return 'p' + id;
		}
	};
	
	Core.setToParentWindow('CategoryHelper', CategoryHelper);
})();